cmake_minimum_required(VERSION 3.16)

project(crypto_framework_unittest LANGUAGES C CXX)

include(${CMAKE_CURRENT_SOURCE_DIR}/common.cmake)

set(SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})

set(CRYPTO_FRAMEWORK_INC
  ${DEPEND_INC}
  ${SOURCE_DIR}/common/inc
  ${SOURCE_DIR}/interfaces/kits/native/include
  ${SOURCE_DIR}/interfaces/inner_api/common
  ${SOURCE_DIR}/interfaces/inner_api/algorithm_parameter
  ${SOURCE_DIR}/interfaces/inner_api/crypto_operation
  ${SOURCE_DIR}/interfaces/inner_api/key
  ${SOURCE_DIR}/frameworks/spi
  ${SOURCE_DIR}/frameworks/native/include
  ${SOURCE_DIR}/plugin/openssl_plugin/common/inc
  ${SOURCE_DIR}/plugin/openssl_plugin/key/sym_key_generator/inc
  ${SOURCE_DIR}/plugin/openssl_plugin/key/asy_key_generator/inc
  ${SOURCE_DIR}/plugin/openssl_plugin/crypto_operation/cipher/inc
  ${SOURCE_DIR}/plugin/openssl_plugin/crypto_operation/hmac/inc
  ${SOURCE_DIR}/plugin/openssl_plugin/crypto_operation/kdf/inc
  ${SOURCE_DIR}/plugin/openssl_plugin/crypto_operation/key_agreement/inc
  ${SOURCE_DIR}/plugin/openssl_plugin/crypto_operation/md/inc
  ${SOURCE_DIR}/plugin/openssl_plugin/crypto_operation/rand/inc
  ${SOURCE_DIR}/plugin/openssl_plugin/crypto_operation/signature/inc
)

# crypto_common
file(GLOB_RECURSE CRYPTO_COMMON_SRC
  ${SOURCE_DIR}/common/*.c
)

add_library(crypto_common SHARED ${CRYPTO_COMMON_SRC})
target_include_directories(crypto_common PRIVATE ${CRYPTO_FRAMEWORK_INC})
target_link_directories(crypto_common PRIVATE ${DEPEND_LIB})
target_link_libraries(crypto_common
  PRIVATE LIB_COMPILE_CONFIG
  PUBLIC LIB_LINK_CONFIG
)

# crypto_openssl_plugin
file(GLOB_RECURSE CRYPTO_OPENSSL_PLUGIN_SRC
  ${SOURCE_DIR}/plugin/openssl_plugin/common/*.c
  ${SOURCE_DIR}/plugin/openssl_plugin/crypto_operation/*.c
  ${SOURCE_DIR}/plugin/openssl_plugin/key/*.c
)

add_library(crypto_openssl_plugin SHARED ${CRYPTO_OPENSSL_PLUGIN_SRC})
target_include_directories(crypto_openssl_plugin PRIVATE ${CRYPTO_FRAMEWORK_INC})
target_link_directories(crypto_openssl_plugin PRIVATE ${DEPEND_LIB})
target_link_libraries(crypto_openssl_plugin
  PRIVATE LIB_COMPILE_CONFIG
  PUBLIC LIB_LINK_CONFIG
)

# crypto_framework
file(GLOB_RECURSE CRYPTO_FRAMEWORK_SRC
  ${SOURCE_DIR}/frameworks/crypto_operation/*.c
  ${SOURCE_DIR}/frameworks/native/src/*.c
  ${SOURCE_DIR}/frameworks/key/*.c
)

add_library(crypto_framework SHARED ${CRYPTO_FRAMEWORK_SRC})
target_include_directories(crypto_framework PRIVATE ${CRYPTO_FRAMEWORK_INC})
target_link_directories(crypto_framework PRIVATE ${DEPEND_LIB})
target_link_libraries(crypto_framework
  PRIVATE LIB_COMPILE_CONFIG
  PUBLIC LIB_LINK_CONFIG
)

set(CRYPTO_FRAMEWORK_TEST_INC
  ${CRYPTO_FRAMEWORK_INC}
  ${SOURCE_DIR}/plugin/openssl_plugin/crypto_operation/signature/src
  ${SOURCE_DIR}/plugin/openssl_plugin/key/asy_key_generator/src
  ${SOURCE_DIR}/test/unittest/include
)

# crypto_framework_test
file(GLOB_RECURSE CRYPTO_FRAMEWORK_TEST_SRC
  ${CRYPTO_COMMON_SRC}
  ${SOURCE_DIR}/test/unittest/src/*.c
  ${SOURCE_DIR}/test/unittest/src/*.cpp
)
list(REMOVE_ITEM CRYPTO_FRAMEWORK_TEST_SRC ${SOURCE_DIR}/common/src/memory.c)

add_executable(crypto_framework_test ${CRYPTO_FRAMEWORK_TEST_SRC})
add_dependencies(crypto_framework_test crypto_openssl_plugin crypto_framework)
target_include_directories(crypto_framework_test PRIVATE ${CRYPTO_FRAMEWORK_TEST_INC})
target_link_directories(crypto_framework_test PRIVATE ${DEPEND_LIB})
target_link_libraries(crypto_framework_test
  PRIVATE EXE_COMPILE_CONFIG
  PUBLIC EXE_LINK_CONFIG crypto_openssl_plugin crypto_framework
)

install(TARGETS crypto_common crypto_openssl_plugin crypto_framework
  LIBRARY DESTINATION lib
)

install(TARGETS crypto_framework_test
  RUNTIME DESTINATION bin
)
